import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_frame/utils/theme_util.dart';
import 'package:flutter_frame/weiget/image_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../assets/color_config.dart';
import '../../weiget/over_scroll_behavior.dart';

class OrderPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => OrderPageState();
}

class OrderPageState extends State {
  var count = 1.obs;
  final RefreshController _refreshController = RefreshController();
  List<String> dataSource = [
    "1",
    "1",
    "1",
    "1",
    "1",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: ColorConfig.colorWhite,
        appBar:AppBar(
          title: Text(
            'order'.tr,
            style: TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 18.sp,
                color: ColorConfig.colorPrimary),
          ),
          elevation: 0,
          systemOverlayStyle: ThemeUtil.dark,
        ),
        extendBodyBehindAppBar: true,
        body: Container(
          color: ColorConfig.colorWhite,
          child: SafeArea(
            child: ScrollConfiguration(
              behavior: OverScrollBehavior(),
              child: SmartRefresher(
                  enablePullUp: true,
                  enablePullDown: true,
                  controller: _refreshController,
                  onRefresh: _onRefresh,
                  onLoading: _onLoading,
                  child: ListView.builder(
                    itemCount: dataSource.length,
                    itemBuilder: (BuildContext context, int index) {
                      return orderItemList(context, index);
                    },
                  )),
            ),
          ),
        ));
  }

  orderItemList(BuildContext context, int index) {
    return Container(
        color: ColorConfig.colorWhite,
        child: Column(
          mainAxisSize: MainAxisSize.max,
          children: [
            Container(height: 10.h, color: ColorConfig.colorF5),
            SizedBox(
              height: 10.w,
            ),
            Row(
              mainAxisSize: MainAxisSize.max,
              children: [
                SizedBox(
                  width: 10.w,
                ),
                Text(
                  'Cloudpick',
                  style: TextStyle(
                      fontSize: 16.sp,
                      color: ColorConfig.colorPrimary,
                      fontWeight: FontWeight.bold),
                ),
                Expanded(
                  child: SizedBox(),
                ),
                Text(
                  '支付成功',
                  style:
                      TextStyle(fontSize: 16.sp, color: ColorConfig.colorGreen),
                ),
                SizedBox(
                  width: 10.w,
                )
              ],
            ),
            Divider(
              thickness: 1.w,
              color: ColorConfig.colorF5,
            ),
            Row(
              children: [
                ImageWidget(
                    url:
                        'https://img.yunatop.com/goods/picture/yunna/00000627.jpg?hash=1708245013379',
                    height: 100.w,
                    fit: BoxFit.fitHeight),
                ImageWidget(
                    url:
                        'https://img.yunatop.com/goods/picture/yunna/00000621.jpg?hash=1708245013381',
                    height: 100.w,
                    fit: BoxFit.fitHeight),
                ImageWidget(
                    url:
                        'https://img.yunatop.com/goods/picture/yunna/00000602.jpg?hash=1708245123103',
                    height: 100.w,
                    fit: BoxFit.fitHeight),
              ],
            ),
            Divider(
              thickness: 1.w,
              color: ColorConfig.colorF5,
            ),
            Row(
              mainAxisSize: MainAxisSize.max,
              children: [
                Expanded(
                  child: SizedBox(),
                ),
                Text(
                  '共3件，付款：',
                  style: TextStyle(
                      fontSize: 16.sp, color: ColorConfig.colorPrimary),
                ),
                Text(
                  'HK¥3.00',
                  style:
                      TextStyle(fontSize: 16.sp, color: ColorConfig.colorRed),
                ),
                SizedBox(
                  width: 10.w,
                )
              ],
            ),
            SizedBox(
              width: 10.w,
            ),
          ],
        ));
  }

  _onRefresh() async {
    loadData();
  }

  _onLoading() async {
    loadData();
  }

  loadData() {
    refreshCompleted();
  }

  void refreshCompleted() {
    _refreshController.refreshCompleted();
    _refreshController.loadComplete();
  }
}
